/* 
 * File:   flash.h
 * Author: Bogdan
 *
 * Created on December 9, 2012, 8:08 PM
 */

#ifndef FLASH_H
#define FLASH_H

//FLASH pins
#define FLS_SDO_TRIS    TRISFbits.TRISF2     //overwritten by SpiInitDevice
#define FLS_SDI_TRIS    TRISFbits.TRISF3     //overwritten by SpiInitDevice
#define FLS_WP_TRIS     TRISFbits.TRISF4
#define FLS_CE_TRIS     TRISFbits.TRISF5
#define FLS_SCK_TRIS    TRISFbits.TRISF6     //overwritten by SpiInitDevice

#define FLS_WP_LAT      LATFbits.LATF4
#define FLS_CE_LAT      LATFbits.LATF5

//flash prototypes
void            ConfigFlash     (void);
void            ClearFlash      (void);
unsigned short  ReadFlash       (unsigned int address);
void            ReadFlashHS     (unsigned int    address ,
                                unsigned char   pack_size,
                                unsigned char   ret_array[]);
unsigned short  ReadFlashStatus (void);
unsigned short  UnprotectFlash  (void);
void            WriteFlash      (unsigned int   address,
                                unsigned char   pack_size,
                                unsigned char   data[]);
void            WriteFlashAAI   (unsigned int   address , //initial address to write at
                                unsigned char   pack_size,
                                unsigned char   data[]);  //data array to write
                                
void            EraseFlash      (void);
unsigned short  ReadFlashID     (void);
unsigned int    ReadFlashJedecID(void);


//delay
void delay_ms(unsigned int delay);

#endif /* FLASH_H */
